package com.frame.common.core.security.config;

import com.frame.stant.constans.ResultCode;
import com.frame.stant.utils.R;
import com.frame.stant.utils.ResponseUtil;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 无效token / 匿名用户不能访问
 */
@Component
public class AnonymousEntryPoint implements AuthenticationEntryPoint {

    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
        ResponseUtil.out(response, R.error(ResultCode.TOKEN_INVALID_OR_EXPIRED));
    }
}
